package com.zheng.damo01.HomeWeark01;

import java.util.*;

public class Test implements Comparable<Student>{
    public static void main(String[] args) {
        ArrayList<Student> list=new ArrayList<>();
        list.add(new Student("zhangsan",20,90.0));
        list.add(new Student("lishi",22,90.0));
        list.add(new Student("wangwu",20,99.0));
        list.add(new Student("zhaoliu",22,100.0));
        List<Student> fraction = new Test().getFraction(list);
        for (Student student : fraction) {
            System.out.println(student);
        }
        System.out.println("通过姓名排序");
        new Test().getname(list);
        for (Student student : fraction) {
            System.out.println(student);
        }


        //System.out.println(new Test().getFraction(list));

    }


    @Override
    public List<Student> getFraction(ArrayList<Student> list) {
        for (int i = 0; i < list.size(); i++) {
            for (int j = 0; j < list.size()-i-1; j++) {
                if (list.get(j).getFraction()<list.get(j+1).getFraction()){
                    if (list.get(i).getFraction().equals(list.get(i+1).getFraction())){
                        Student tamp=list.get(j);
                        list.set(j,list.get(j+1));
                        list.set(j+1,tamp);
                    }else {
                        Student tamp=list.get(j);
                        list.set(j,list.get(j+1));
                        list.set(j+1,tamp);
                    }

                }
            }

        }
        return list;
    }

    @Override
    public void getname(ArrayList<Student> list) {
        Collections.sort(list, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o1.getName().compareTo(o2.getName());
            }
        });

    }
}
